home *** CD-ROM | disk | FTP | other *** search
/ Amiga News 95 / Amiga News 95.iso / dpat / dpat31 / iobject / sources.lha / sources / Cycle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-23  |  4.9 KB  |  245 lines

  1. // Gestionnaire de Cycle gadget V0.41
  2. // (C) 1992 Christophe PASSUELLO
  3. // Mon Jan 25 21:20:14 1993
  4.  
  5. #include <exec/types.h>
  6. #include <exec/memory.h>
  7. #include "mytypes.h"
  8. #define  INTUITION_PREFERENCES_H 0
  9. #include <intuition/intuition.h>
  10. #include "IObject_priv.h"
  11.  
  12.  
  13. IMPORT UBYTE DarkPen, LightPen, Pen1;
  14.  
  15.  
  16. struct Cycle
  17. {
  18.     struct ObjectTMV *TMV;
  19.     UWORD  ObjectID;
  20.     UWORD  Flags;
  21.     STRPTR LabelText;
  22.     struct TextFont *Font;
  23.     struct Window *window;
  24.     struct Requester *requester;
  25.     UWORD  ClassFlags;
  26.     struct Box BorderBox;
  27.     struct Gadget Gadget;
  28.     STRPTR *TextArray;
  29.     UWORD  ActiveText;
  30.     struct Box TextBox;
  31. };
  32.  
  33. // procedures privees
  34. PRIVATE VOID DisplayInner(struct Cycle *);
  35.  
  36. // prototypes pour les methodes
  37. PRIVATE BOOL CycleMsg(struct Cycle *, struct IntuiMessage *);
  38. VOID ModifyCycle(struct Cycle *, STRPTR *, ULONG);
  39. PRIVATE VOID DisplayCycle(struct Cycle *);
  40. PRIVATE VOID EraseCycle(struct Cycle *);
  41. PRIVATE UWORD CycleValue(struct Cycle *);
  42. PRIVATE VOID OnCycle(struct Cycle *);
  43. PRIVATE VOID ActivateCycle(struct Cycle *);
  44.  
  45.  
  46. // Methodes pour les Cycles
  47. const static struct ObjectTMV CycleMethod=
  48. {
  49.     CLASS_CYCLE, sizeof(struct Cycle),
  50.     DisposeObject, CycleMsg, AddObject, RemoveObject, DisplayCycle, EraseCycle,
  51.     ModifyCycle, CycleValue, OffObjectGad, OnCycle, ActivateCycle
  52. };
  53.  
  54.  
  55. IMPORT struct Image CycleImage;
  56.  
  57. #define IMAGEWIDTH    18
  58.  
  59. //
  60. // Alloue et Initialise le Cycle
  61. //
  62. struct Cycle *CreateCycle(struct NewCycle *nc, UWORD ID)
  63. {
  64.     struct Cycle *cy;
  65.  
  66.     if (cy = (struct Cycle *) AllocMem(sizeof(struct Cycle), MEMF_PUBLIC|MEMF_CLEAR))
  67.     {
  68.         // Initialise la TMV
  69.         cy->TMV = &CycleMethod;
  70.         cy->ObjectID = ID;
  71.  
  72.         // recupere les champs de NewCycle
  73.         InitObjectGad( (struct ObjectGad *) cy, (struct NewObject *) nc);
  74.         cy->TextArray = nc->TextArray;
  75.  
  76.         // Ajuste les boites
  77.         COPY_BOX(&cy->TextBox, &cy->Gadget.LeftEdge);
  78.         AdjustBox(&cy->TextBox, TRUE);
  79.  
  80.         // initialise le gadget
  81.         cy->Gadget.Flags = GADGHCOMP;
  82.         cy->Gadget.Activation = RELVERIFY;
  83.         cy->Gadget.GadgetType = BOOLGADGET;
  84.  
  85.         // correction pour la TextBox
  86.         cy->TextBox.x += (IMAGEWIDTH-2);
  87.         cy->TextBox.w -= (IMAGEWIDTH-2);
  88.     }
  89.     return (cy);
  90. }
  91.  
  92.  
  93. //
  94. // Renvoie l'index du texte actif
  95. //
  96. PRIVATE UWORD CycleValue(struct Cycle *cy)
  97. {
  98.     return (cy->ActiveText);
  99. }
  100.  
  101.  
  102. //
  103. // Simule l'activation d'un cycle
  104. //
  105. PRIVATE VOID ActivateCycle(struct Cycle *cy)
  106. {
  107.     UWORD index;
  108.  
  109.     // Calcule le texte a afficher
  110.     if (cy->TextArray[cy->ActiveText + 1])
  111.         index = cy->ActiveText + 1;
  112.     else
  113.         index = 0;
  114.  
  115.     // affiche le texte
  116.     ModifyCycle(cy, NULL, index);
  117. }
  118.  
  119.  
  120. //
  121. // Change le texte a afficher
  122. //
  123. PRIVATE VOID ModifyCycle(struct Cycle *cy, STRPTR *array, ULONG number)
  124. {
  125.     struct TextEnv env;
  126.     struct RastPort *rp;
  127.  
  128.     // on modifie le tableau ssi on a fourni un tableau
  129.     if (array)
  130.         cy->TextArray = array;
  131.  
  132.     // initialise l'index
  133.     if (cy->TextArray[number])
  134.         cy->ActiveText = number;
  135.     else
  136.         cy->ActiveText = 0;
  137.  
  138.     if (!(cy->Flags & OBJ_DISABLED))
  139.     {
  140.         rp = cy->window->RPort;
  141.         SaveTextEnv(rp, &env);
  142.  
  143.         // on efface le texte courant
  144.         FastEraseBox(&cy->TextBox, rp);
  145.  
  146.         // affiche le texte
  147.         SetAPen(rp, Pen1);
  148.         SetFont(rp, cy->Font);
  149.         PrintLabelText(rp, &cy->TextBox, cy->TextArray[cy->ActiveText], LABEL_INSIDE);
  150.         RestoreTextEnv(rp, &env);
  151.     }
  152. }
  153.  
  154.  
  155. //
  156. // Gestion de l'IntuiMessage pour le Cycle
  157. //
  158. PRIVATE BOOL CycleMsg(struct Cycle *cy, struct IntuiMessage *msg)
  159. {
  160.     ActivateCycle(cy);
  161.     return (TRUE);
  162. }
  163.  
  164.  
  165. //
  166. // Affiche le Cycle en entier
  167. //
  168. PRIVATE VOID DisplayCycle(struct Cycle *cy)
  169. {
  170.     struct TextEnv env;
  171.     struct RastPort *rp;
  172.  
  173.     // verifie que le Cycle est dans une fenetre
  174.     if (cy->window)
  175.     {
  176.         rp = cy->window->RPort;
  177.         SaveTextEnv(rp, &env);
  178.  
  179.         DisplayInner(cy);
  180.  
  181.         FastDraw3DBox((struct Box *) &cy->BorderBox, rp, BOX_1OUT);
  182.         PrintObjectLabel( (struct Object *) cy, &cy->BorderBox);
  183.         RestoreTextEnv(rp, &env);
  184.  
  185.         if (cy->Flags & OBJ_DISABLED)
  186.             OffObjectGad( (struct ObjectGad *) cy);
  187.     }
  188. }
  189.  
  190.  
  191. //
  192. // Efface le Cycle
  193. //
  194. PRIVATE VOID EraseCycle(struct Cycle *cy)
  195. {
  196.     EraseObjectFrame( (struct Object *) cy, (struct Box *) &cy->BorderBox);
  197. }
  198.  
  199.  
  200. //
  201. // Affiche l'interieur du cycle
  202. //
  203. PRIVATE VOID DisplayInner(struct Cycle *cy)
  204. {
  205.     struct RastPort *rp;
  206.  
  207.     rp = cy->window->RPort;
  208.  
  209.     SetAPen(rp, DarkPen);
  210.     Move(rp, cy->BorderBox.x + 16, cy->BorderBox.y + 2);
  211.     Draw(rp, cy->BorderBox.x + 16, cy->BorderBox.y + cy->BorderBox.h - 3);
  212.  
  213.     SetAPen(rp, LightPen);
  214.     Move(rp, cy->BorderBox.x + 17, cy->BorderBox.y + 2);
  215.     Draw(rp, cy->BorderBox.x + 17, cy->BorderBox.y + cy->BorderBox.h - 3);
  216.  
  217.     DrawImage(rp, &CycleImage, cy->BorderBox.x, cy->BorderBox.y);
  218.     SetAPen(rp, Pen1);
  219.     SetFont(rp, cy->Font);
  220.     PrintLabelText(rp, &cy->TextBox, cy->TextArray[cy->ActiveText], LABEL_INSIDE);
  221. }
  222.  
  223.  
  224. //
  225. // Unghoste un cycle
  226. //
  227. PRIVATE VOID OnCycle(struct Cycle *cy)
  228. {
  229.     struct TextEnv env;
  230.     struct RastPort *rp;
  231.  
  232.     if (cy->Flags & OBJ_DISABLED)
  233.     {
  234.         rp = cy->window->RPort;
  235.  
  236.         OnGadget(&cy->Gadget, cy->window, cy->requester);
  237.         cy->Flags &= (~OBJ_DISABLED);
  238.  
  239.         SaveTextEnv(rp, &env);
  240.         FastEraseBox((struct Box *) &cy->Gadget.LeftEdge, rp);
  241.         DisplayInner(cy);
  242.         RestoreTextEnv(rp, &env);
  243.     }
  244. }
  245.